<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        /* .vip6{
            color:rgb(255, 179, 0);
            font-size: 25px;
            -webkit-text-stroke-color: red; 
            -webkit-text-stroke-width: 0.75px; 
        } */
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" id="username" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <!-- <div class="layui-inline">
                            <label class="layui-form-label">用户电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tel" autocomplete="off" class="layui-input">
                            </div>
                        </div> -->
                        
                        <div class="layui-inline">
                            <button type="submit" id="do_search" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/jquery-1.8.3.min.js" charset="utf-8"></script>

<!-- <script type="text/html" class="shouji_id">
    {{#  if(d.shouji_id == 0){ }}
    <center><span style="width:10px;height:10px;" class="layui-badge-dot layui-bg-gray"></span>&nbsp;<span>离线</span></center>
    {{#  } else if(d.shouji_id == 1){ }}
    <center><span style="width:10px;height:10px;" class="layui-badge-dot layui-bg-green"></span>&nbsp;<span>在线</span></center>
    {{#  } }}

  </script> -->
  <script type="text/html" class="vip">
    {{#  if(d.vip == 0){ }}
    <center><div class="ming">vip0</div></center>
    {{#  } else if(d.vip == 1){ }}
    <center><div class="ming">vip1</div></center>
    {{#  } else if(d.vip == 2){ }}
    <center><div class="ming">vip2</div></center>
    {{#  } else if(d.vip == 3){ }}
    <center><div class="ming">vip3</div></center>
    {{#  } else if(d.vip == 4){ }}
    <center><div class="ming">vip4</div></center>
    {{#  } else if(d.vip == 5){ }}
    <center><div class="ming">vip5</div></center>
    {{#  } else if(d.vip == 6){ }}
    <center><div class="ming">vip6</div></center>
    {{#  } }}
    
  </script>

  <script type="text/javascript">
    var int=self.setInterval("clock()",200);
    var s='orange';
    function clock()
    {
    // if(s=='orange'){
    // 	$('.ming').css({'border-top':'2px solid orange','border-radius':'30px','border-bottom':'2px solid orange','border-left':'2px solid red','border-right':'2px solid red'});
    // 	$('.xing').css({'border-top':'2px solid orange','border-radius':'30px','border-bottom':'2px solid orange','border-left':'2px solid red','border-right':'2px solid red'});
    //     s='s';
    // }else{
    // 	$('.ming').css({'border-top':'2px solid red','border-radius':'30px','border-bottom':'2px solid red','border-left':'2px solid orange','border-right':'2px solid orange'});
    // 	$('.xing').css({'border-top':'2px solid orange','border-radius':'30px','border-bottom':'2px solid orange','border-left':'2px solid red','border-right':'2px solid red'});
    //     s='orange';
    // }
        if(s=='orange'){
            $('.ming').css({'color':'red','font-size': '25px','-webkit-text-stroke-color': 'red','-webkit-text-stroke-width': '0.75px'});

        s = 'green';
        }else if(s=='green'){
            $('.ming').css({'color':'blue','font-size': '25px','-webkit-text-stroke-color': 'blue','-webkit-text-stroke-width': '0.75px'});
        s = 'blue';
        }else if(s=='blue'){
            $('.ming').css({'color':'green','font-size': '25px','-webkit-text-stroke-color': 'green','-webkit-text-stroke-width': '0.75px'});
        s = 'red';
        }else if(s=='red'){
            $('.ming').css({'color':'orange','font-size': '25px','-webkit-text-stroke-color': 'orange','-webkit-text-stroke-width': '0.75px'});
        s = 'orange';
        }
    }
</script>

<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            // id: 'tableOne', 
            url: '/houtai/table_user_cha',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'name', width: 120, title: '真实姓名'},
                {field: 'username', width: 120, title: '用户名'},
                {field: 'password', width: 120, title: '密码', sort: true},
                {field: 'tel', width: 180, title: '电话'},
                {field: 'balance', title: '账户余额', minWidth: 150},
                {field: 'unused', width: 180, title: '充值总额度', sort: true},
                {field: 'vip', width: 120, title: 'vip等级',templet:'.vip'},
                {title: '操作', minWidth: 50, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [1, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            // layer.alert(result, {
            //     title: '最终的搜索信息'
            // });
            search_shuju = result;
            var ssks = {};
            ssks['page'] = 1;
            ssks['limit'] = 15;
            ssks = JSON.stringify(ssks,true);
            console.log(ssks);
            //执行搜索重载
            table.reload('currentTableId', {
                method: 'post'
                ,page: {
                    curr: 1
                }
                , where: {
                    searchParams: result,
                    'username':$('#username').val
                }
            }, 'data');
            layer.msg('搜索完毕',{
	            	icon: 6,
	            	time: 2000,
					});
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/houtai/add_user',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                // layer.alert(JSON.stringify(data));
                $.post("/houtai/index/delete_user_max",{data},function(delete_bool){
                        if(delete_bool['zhuangtai']=='删除成功'){
                            // layer.msg(delete_bool['zhuangtai'], {icon: 6});
                            layer.msg(delete_bool['zhuangtai']+',正在刷新表格',{
                            icon: 6,
                            time: 1500,
                            end:function(){
                                location.href='table_user';
                            }});
                        }else{
                            layer.msg(delete_bool['zhuangtai'], {icon: 5});
                        }
                        // alert();
                        // obj.del();
                    });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var delete_id = obj['data']['id'];
            console.log(
                delete_id
            );
            
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/houtai/add_user/?id='+delete_id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    console.log(obj['data']['id'])
                    $.post("/houtai/index/delete_user",{delete_id},function(delete_bool){
                        if(delete_bool['zhuangtai']=='删除成功'){
                            layer.msg(delete_bool['zhuangtai'], {icon: 6});
                        }else{
                            layer.msg(delete_bool['zhuangtai'], {icon: 5});
                        }
                        // alert();
                        obj.del();
                    });
                    
                    
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>